package com.xyd.Service;

import com.xyd.bean.ChildCategory;
import com.xyd.bean.ParentCategory;
import com.xyd.bean.Product;
import com.xyd.dao.ChildCategoryMapper;
import com.xyd.dao.ParentCategoryMapper;
import com.xyd.dao.ProductMapper;

import com.xyd.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ProductService {
    SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
    ProductMapper productMapper = sqlSession.getMapper(ProductMapper.class);
    ParentCategoryMapper parentCategoryMapper = sqlSession.getMapper(ParentCategoryMapper.class);
    ChildCategoryMapper childCategoryMapper = sqlSession.getMapper(ChildCategoryMapper.class);

    public List<Product> getAll() {
        return productMapper.getAll();
    }

    public List<ParentCategory> getParentAll() {
        return parentCategoryMapper.getAllParentCategory();
    }

    public List<ChildCategory> getByParentId(Integer parentId) {
        return childCategoryMapper.getAllByParentId(parentId);
    }

    public List<Product> getProductByCId(int childid) {
        return productMapper.getProductByCId(childid);
    }

    public int addProduct(Product product) {
        return productMapper.insertAll(product);
    }

    public Product getById(Integer id) {
        return productMapper.getById(id);
    }

    public int modifyProduct(Product product) {
        return productMapper.updateById(product);
    }

    public int delProduct(Integer id) {
        return productMapper.delById(id);
    }

    public Product getProductById(int id) {
        return productMapper.getProductById(id);
    }

    //修改库存
    public int updateStock(Product product){
        return productMapper.updateStock(product);
    }

}
